import React from 'react';
import ReactDOM from 'react-dom'
import './select.less';

export default class Select extends React.Component {
    constructor(props){
        super(props)
        this.state={}
    }
    getValue(e){
        if(this.props.onChange){
            this.props.onChange(e.target.value)
        }
    }
    render() {
        var { label, id, data, value } = this.props
        return <div className ="select-group">
            {label?<label htmlFor={id}>{label}：</label>:null}
            <select className="tederen-select" name={id} id={id} onChange={this.getValue.bind(this)} value={value}>
                {
                    data.map((opt,i)=>{
                        if((typeof opt=='string')&&opt.constructor==String){
                            return <option value={opt} key={i}>{opt}</option>
                        }else{
                            return <option value={opt.value} key={i}>{opt.keyword}</option>
                        }
                    })
                }
            </select>
        </div>
    }
}

Select.defaultProps = {}
